package com.bw.a1908.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bw.a1908.R;
import com.bw.a1908.bean.VideoBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class VideoFullScreenAdapter extends BaseQuickAdapter<VideoBean, BaseViewHolder> {


    public VideoFullScreenAdapter(@Nullable List<VideoBean> data) {
        super(R.layout.item_video_3, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, VideoBean videoBean) {
        StandardGSYVideoPlayer videoPlayer = baseViewHolder.getView(R.id.item_video_player);
        videoPlayer.setUp(videoBean.videopath, true, "");
        videoPlayer.setLooping(true);
        //添加封面层
        videoPlayer.setThumbImageView(getThumbView(videoBean.videomainimg));
        //隐藏返回
        videoPlayer.getBackButton().setVisibility(View.GONE);
    }

    /**
     * 构建封面
     */
    private ImageView getThumbView(String url) {
        ImageView thumbIv = new ImageView(getContext());
        thumbIv.setScaleType(ImageView.ScaleType.CENTER_CROP);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        thumbIv.setLayoutParams(params);
        Glide.with(getContext()).load(url)
                .error(R.mipmap.top)
                .placeholder(R.mipmap.top)
                .into(thumbIv);
        return thumbIv;
    }
}
